package com.test.flink_introduction;

import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.ExecutionMode;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 第一步 获取环境
 * 第二部 获取数据流 source
 * 第三步 调用算子处理 Transform
 * 第四步 输出 sink
 */
public class F03Enviroment {

    public static void main(String[] args) throws Exception {
        //1 获取批处理数据的环境 只能处理批数据
        ExecutionEnvironment ee = ExecutionEnvironment.getExecutionEnvironment();

        //2 获取流批一体处理数据的环境（实际生成中使用）
        StreamExecutionEnvironment sse = StreamExecutionEnvironment.getExecutionEnvironment();
        ExecutionConfig config = sse.getConfig();
        config.setExecutionMode(ExecutionMode.BATCH);
        config.setExecutionMode(ExecutionMode.PIPELINED);
        // 3 学习测试时一个本地带web界面的
        Configuration configuration = new Configuration();
        configuration.setInteger("rest.port",8888);
        StreamExecutionEnvironment webUI = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(configuration);
        DataStreamSource<String> data = webUI.socketTextStream("127.0.0.1", 8899);
        data.print() ;
        webUI.execute("编程环境") ;
    }

}
